<template>
  <div>
    <q-btn :label="button" @click="confirm(button)" style="color: #fff; background-color: #dbb22e" />
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, PropType } from 'vue';

import { emitter } from 'src/emitter';

export default defineComponent({
  name: 'confirm-button',

  props: {
    params: {
      type: Object as PropType<{ data: any }>,
    },
  },

  setup(props) {
    const button = computed(() => {
      if (props.params?.data.orderStatus == '11') {
        return '取消选中';
      } else if (props.params?.data.orderStatus == '2') {
        return '选中';
      } else if (props.params?.data.orderStatus == '13') {
        return '卸下';
      } else {
        return props.params?.data.orderStatus ?? '取消选中';
      }
    });

    const confirm = async (val: any) => {
      let operType = '';
      if (val == '选中') {
        operType = '3';
      } else if (val == '取消选中') {
        operType = '4';
      } else if (val == '卸下') {
        operType = '2';
      }

      emitter.emit('inform', {
        name: 'production-table-confirm',
        value: {
          orderNo: props.params?.data.orderNo,
          operType: operType,
          frPos: props.params?.data.frPos,
        },
      });
    };
    return { button, confirm };
  },
});
</script>
